import { BaseEntity } from '../../base/entity/base';
import { Column, Entity, Index } from 'typeorm';

/**
 * 订单信息
 */
@Entity('order_info')
export class OrderInfoEntity extends BaseEntity {
  
  @Column({ comment: '订单号', length: 50, default: 0 })
  orderNumber: string;

  @Index()
  @Column({ comment: '用户ID' })
  userId: number;

  @Column({ comment: '店铺ID', default: 0 })
  shopId: number;

  @Column({
    comment: '总金额',
    type: 'decimal',
    precision: 10,
    scale: 2,
    default: 0.0,
  })
  totalAmount: number;

  @Column({
    comment: '优惠金额',
    type: 'decimal',
    precision: 10,
    scale: 2,
    default: 0,
  })
  discountAmount: number;

  @Column({
    comment: '支付金额',
    type: 'decimal',
    precision: 10,
    scale: 2,
    default: 0,
  })
  payAmount: number;

  @Column({
    comment: '状态',
    dict: ['待支付', '已支付', '已发货', '已完成', '已取消'],
    default: 0,
  })
  status: number;

  @Column({
    comment: '支付方式',
    dict: ['现金', '微信', '支付宝', '银行卡'],
    default: 0,
  })
  payType: number;

  @Column({ comment: '销售', nullable: true })
  sales: string;

  @Column({ comment: '档案号', nullable: true })
  filesNumber: string;

  @Column({ comment: '病历号', nullable: true })
  caseNumber: string;

  @Column({ comment: '瞳距', nullable: true })
  pupilDistance: string;

  @Column({ comment: '曈高', nullable: true })
  pupilHeight: string;

  @Column({ comment: 'OD', nullable: true })
  OD: string;

  @Column({ comment: 'OS', nullable: true })
  OS: string;

  @Column({ comment: '到店日期', type: 'varchar', nullable: true })
  comeDate: Date;

  @Column({ comment: '取镜日期', type: 'varchar', nullable: true })
  takeDate: Date;

  @Column({ comment: '备注', nullable: true })
  remark: string;

  @Column({ comment: '商品IDS', type: 'json', nullable: true })
  ProductIds: number[];
  
  @Column({
    comment: '商品金额',
    type: 'decimal',
    precision: 10,
    scale: 2,
    default: 0.0,
  })
  productAmount: number;

  @Column({ comment: '套餐IDS', type: 'json', nullable: true })
  ComboIds: number[];
  
  @Column({
    comment: '套餐金额',
    type: 'decimal',
    precision: 10,
    scale: 2,
    default: 0.0,
  })
  packageAmount: number;

  @Column({ 
    comment: '商品详情', 
    type: 'json', 
    nullable: true 
  })
  productDetails: Array<{
    id: number;
    name: string;
    price: number;
    type: number;
  }>;

  @Column({ 
    comment: '优惠详情', 
    type: 'json', 
    nullable: true 
  })
  discountDetails: Array<{}>;

  @Column({ comment: '下单时间', type: 'datetime', nullable: true })
  orderTime: Date;

  @Column({ comment: '支付时间', type: 'datetime', nullable: true })
  payTime: Date;

  @Column({ comment: '收货地址', nullable: true })
  address: string;

  @Column({ comment: '收货人', nullable: true, length: 50 })
  consignee: string;

  @Column({ comment: '联系电话', nullable: true, length: 20 })
  phone: string;

  @Column({ comment: '省', nullable: true })
  province: string;

  @Column({ comment: '市', nullable: true })
  city: string;

  @Column({ comment: '区', nullable: true })
  district: string;

  @Column({ comment: '支付截图', nullable: true })
  payImg: string;

  // 添加微信支付相关字段
  @Column({ comment: '微信支付商户号', nullable: true, length: 32 })
  mchId: string;

  @Column({ comment: '微信支付订单号', nullable: true, length: 32 })
  transactionId: string;

  @Column({ comment: '微信支付预支付ID', nullable: true, length: 64 })
  prepayId: string;

  @Column({ comment: '微信支付二维码链接', nullable: true })
  codeUrl: string;

  @Column({ comment: '微信支付H5链接', nullable: true })
  h5Url: string;

  @Column({ comment: '微信支付小程序支付参数', type: 'json', nullable: true })
  miniPayParams: {
    appId: string;
    timeStamp: string;
    nonceStr: string;
    package: string;
    signType: string;
    paySign: string;
  };

  @Column({ comment: '支付失败原因', nullable: true })
  failReason: string;

  @Column({ 
    comment: '支付状态', 
    dict: ['未支付', '支付中', '支付成功', '支付失败', '已退款'],
    default: 0 
  })
  payStatus: number;

  @Column({ comment: '退款金额', type: 'decimal', precision: 10, scale: 2, default: 0 })
  refundAmount: number;

  @Column({ comment: '退款时间', type: 'datetime', nullable: true })
  refundTime: Date;

  @Column({ comment: '退款单号', nullable: true, length: 32 })
  refundNo: string;
}
